home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / Think Class Libraries / WASTE TCL 1.8 / WASTE TCL 1.8 ƒ / CWASTEDlgText.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1995-11-12  |  7.7 KB  |  329 lines  |  [TEXT/MMCC]

  1. /******************************************************************************
  2.  CWASTEDlgText.cpp
  3.  
  4.     A class with some of the functionality of CDialogText, but using CWASTEText
  5.  
  6.     by Dan Crevier
  7.     version 1.8
  8.  
  9.     Roms    95/11/08    adapted to THINK C / TCL 1.1.3
  10.  ******************************************************************************/
  11.  
  12. #ifdef TCL_PCH
  13. #include <TCLHeaders>
  14. #endif
  15.  
  16. #include "CWASTEDlgText.h"
  17. #include "CDialog.h"
  18. #include <CPaneBorder.h>
  19. #include "CBartender.h"
  20. #include "Constants.h"
  21. #include "CTextEditTask.h"
  22.  
  23. #define kBorderAmount    2    // white space between border and text of edit field
  24.  
  25. extern CBartender    *gBartender;
  26. extern CBureaucrat        *gGopher;        // First in line to get commands
  27.  
  28. static pascal void WEPostUpdate(WEHandle hWE, long fixLength, long inputAreaStart,
  29.     long inputAreaEnd, long pinRangeStart, long pinRangeEnd);
  30.  
  31. #if TCL_VERSION >= 0x02000000
  32. TCL_DEFINE_CLASS_D1(CWASTEDlgText, CWASTEText);
  33. #endif
  34.  
  35. #ifndef THINK_C
  36. /********************************************************\
  37.  CWASTEDlgText - default constructor
  38. \********************************************************/
  39.  
  40. CWASTEDlgText::CWASTEDlgText()
  41. {
  42.     TCL_END_CONSTRUCTOR
  43. }
  44.  
  45.  
  46. /********************************************************\
  47.  CWASTEDlgText - constructor
  48. \********************************************************/
  49.  
  50. CWASTEDlgText::CWASTEDlgText(
  51.     CView            *anEnclosure,
  52.     CBureaucrat        *aSupervisor,
  53.     short            aWidth,
  54.     short            aHeight,
  55.     short            aHEncl,
  56.     short            aVEncl,
  57.     SizingOption    aHSizing,
  58.     SizingOption    aVSizing,
  59.     short            aLineWidth,
  60.     Boolean        aScrollHoriz,
  61.     Boolean        aIsRequired,
  62.     long            aMaxValidLength,
  63.     Boolean        aValidateOnResign,
  64.     Boolean        supportObjects,
  65.     Boolean        supportUndo,
  66.     Boolean        supportDragAndDrop,
  67.     Boolean        outlineHighliting,
  68.     Boolean        drawOffscreen)
  69.  
  70.     : CWASTEText(anEnclosure, aSupervisor,
  71.         aWidth, aHeight, aHEncl, aVEncl,
  72.         aHSizing, aVSizing, aLineWidth, aScrollHoriz, NULL, supportObjects,
  73.         supportUndo, supportDragAndDrop, outlineHighliting, drawOffscreen)
  74. {
  75.  
  76.     IWASTEDlgTextX();
  77.     TCL_END_CONSTRUCTOR
  78. }
  79.  
  80.  
  81. /********************************************************\
  82.  ~CWASTEDlgText - destructor
  83. \********************************************************/
  84.  
  85. CWASTEDlgText::~CWASTEDlgText()
  86. {
  87.     TCL_START_DESTRUCTOR
  88. }
  89.  
  90. #endif    // THINK_C
  91.  
  92. /********************************************************\
  93.  IWASTEDlgText - initializer, if used with default
  94.      constructor
  95. \********************************************************/
  96.  
  97. void CWASTEDlgText::IWASTEDlgText(CView *anEnclosure, CBureaucrat *aSupervisor,
  98.                 short aWidth, short aHeight,
  99.                 short aHEncl, short aVEncl,
  100.                 SizingOption aHSizing, SizingOption aVSizing,
  101.                 short aLineWidth)
  102. {
  103.  
  104.     CWASTEText::IWASTEText(anEnclosure, aSupervisor,
  105.         aWidth, aHeight, aHEncl, aVEncl,
  106.         aHSizing, aVSizing, aLineWidth
  107. #ifdef THINK_C
  108.         ,
  109.         NULL,
  110.         true,
  111.         true,
  112.         true,
  113.         true,
  114.         false
  115. #endif // THINK_C
  116.         );
  117.  
  118.     IWASTEDlgTextX();
  119. }
  120.  
  121.  
  122. /********************************************************\
  123.  IViewTemp - construct from View resource
  124. \********************************************************/
  125.  
  126. void CWASTEDlgText::IViewTemp(CView *anEnclosure, CBureaucrat *aSupervisor,
  127.                             Ptr viewData)
  128. {
  129.     CWASTEText::IViewTemp(anEnclosure, aSupervisor, viewData);
  130.  
  131.     IWASTEDlgTextX();
  132. }
  133.  
  134.  
  135. /********************************************************\
  136.  IWASTEDlgTextX - common initialization
  137. \********************************************************/
  138.  
  139. void CWASTEDlgText::IWASTEDlgTextX()
  140. {
  141. #if WASTE_VERSION >= 0x01100000
  142.     static WETSMPostUpdateUPP    postProc = NULL;
  143. #else
  144.     WETSMPostUpdateProcPtr postProc;
  145. #endif
  146.  
  147.     MakeBorder();
  148.     SetWholeLines(FALSE);
  149.     
  150.     // set postupdate routine to WEPostUpdate
  151. #if WASTE_VERSION >= 0x01100000
  152.     if (postProc == NULL)
  153.         postProc = NewWETSMPostUpdateProc(WEPostUpdate);
  154. #else
  155.     postProc = &WEPostUpdate;
  156. #endif
  157.     WESetInfo(weTSMPostUpdate, (Ptr)&postProc, macWE);
  158. }
  159.  
  160. /********************************************************\
  161.  WEPostUpdate -- broadcast a dialog text changed message
  162. \********************************************************/
  163.  
  164.  pascal void CWASTEDlgText::WEPostUpdate(WEHandle hWE, long fixLength, long inputAreaStart,
  165.     long inputAreaEnd, long pinRangeStart, long pinRangeEnd)
  166. {
  167.     short ID;
  168.     GrafPtr curPort;
  169.     CWASTEText *itsOwner = NULL;
  170.  
  171.     WEGetInfo(weRefCon, (Ptr)&itsOwner, hWE);
  172. #if TCL_VERSION >= 0x02000000
  173.     TCL_ASSERT_OBJECT_PTR(itsOwner);
  174.     TCL_ASSERT(member(itsOwner, CWASTEText));
  175. #else
  176.     ASSERT(member(itsOwner, CWASTEText));
  177. #endif
  178.     
  179.     CWASTEText::WEPostUpdate(hWE, fixLength, inputAreaStart, inputAreaEnd, pinRangeStart,
  180.         pinRangeEnd);
  181.         
  182.     if (itsOwner != NULL)
  183.     {
  184.         GetPort(&curPort);
  185.         ID = itsOwner->ID;
  186.         itsOwner->BroadcastChange(dialogTextChanged, &ID);
  187.         SetPort(curPort);
  188.         itsOwner->Prepare();
  189.     }
  190. }
  191.  
  192.  
  193. /********************************************************\
  194.  MakeBorder - put a border around the text
  195. \********************************************************/
  196.  
  197. void CWASTEDlgText::MakeBorder()
  198. {
  199.     Rect    margin;
  200.     CPaneBorder *border;
  201.  
  202. #if TCL_VERSION >= 0x02000000
  203.     border = TCL_NEW(CPaneBorder,());
  204. #else
  205.     border = new (CPaneBorder);
  206. #endif
  207.  
  208.     border->IPaneBorder(kBorderFrame);
  209.     SetRect(&margin, -kBorderAmount, -kBorderAmount, kBorderAmount, kBorderAmount);
  210.     border->SetMargin(&margin);
  211.     SetBorder(border);
  212. }
  213.  
  214. /********************************************************\
  215.  DoKey - handle Tab and Return
  216. \********************************************************/
  217.  
  218. void CWASTEDlgText::DoKeyDown(char theChar, Byte keyCode, EventRecord *macEvent)
  219. {
  220.     Boolean pass = TRUE;
  221.     short    ID;
  222.  
  223.     switch (theChar)
  224.     {
  225.         case '\t':
  226.         case '\r':
  227.         case kEnterKey:
  228.             pass = FALSE;
  229.             break;
  230.  
  231.         case kEscapeOrClear:
  232.             if (keyCode == KeyEscape) pass = FALSE;
  233.             break;
  234.     }
  235.     if (pass)
  236.     {
  237.         CWASTEText::DoKeyDown(theChar, keyCode, macEvent);
  238.  
  239. #if WASTE_VERSION >= 0x01100000
  240.         { // I'm not sure of the right thing to do here -- check mod counts?
  241. #else
  242.         if (itsTypingTask && itsTypingTask->CanStillType())
  243.         {
  244. #endif
  245.             ID = this->ID;
  246.             BroadcastChange(dialogTextChanged, &ID);
  247.         }
  248.     }
  249.     else
  250.         itsSupervisor->DoKeyDown(theChar, keyCode, macEvent);
  251. }
  252.  
  253. /********************************************************\
  254.  GetTextString - return the text as a pascal string
  255. \********************************************************/
  256.  
  257. void CWASTEDlgText::GetTextString(StringPtr aString)
  258. {
  259.     short length = Min(GetLength(), 255);
  260.  
  261.     StopInlineSession();
  262.     BlockMove(*GetTextHandle(), &aString[1], length);
  263.     aString[0] = length;
  264. }
  265.  
  266. /********************************************************\
  267.  PerformEditCommand - handle cut, copy, paste, and clear
  268.      -- check for text changed
  269. \********************************************************/
  270.  
  271. void CWASTEDlgText::PerformEditCommand(long theCommand)
  272. {
  273.     short    ID;
  274.  
  275.     CWASTEText::PerformEditCommand(theCommand);
  276.  
  277.     switch( theCommand)
  278.     {        
  279.         case cmdCut:
  280.         case cmdPaste:
  281.         case cmdClear:
  282.             ID = this->ID;
  283.             BroadcastChange(dialogTextChanged, &ID);
  284.             break;
  285.         
  286.         default:
  287.             break;
  288.     }
  289.  
  290. }
  291.  
  292. #if VA_COMPATIBLE_IO
  293.  
  294. /******************************************************************************
  295.  PutTo
  296.         Put the contents of this object to the stream
  297.  ******************************************************************************/
  298.  
  299. void CWASTEDlgText::PutTo(CStream& stream)
  300. {
  301. #ifdef TCL_OBJECT_IO
  302.     // write made up values
  303.     stream << (long)0 << (Boolean) false << (Boolean) false;
  304.     CWASTEText::PutTo(stream);
  305. #endif
  306. }
  307.  
  308.  
  309. /******************************************************************************
  310.  GetFrom
  311.  
  312.         Get the contents of this object from the stream and
  313.         initialize the object
  314.  ******************************************************************************/
  315.  
  316. void CWASTEDlgText::GetFrom(CStream& stream)
  317. {
  318. #ifdef TCL_OBJECT_IO
  319.     Boolean required, validate;
  320.     long maxValidLength;
  321.  
  322.     // note, values are ignored
  323.     stream >> maxValidLength >> required >> validate;
  324.  
  325.     CWASTEText::GetFrom(stream);
  326. #endif
  327. }
  328.  
  329. #endif // VA_COMPATIBLE_IO